#ifndef TDOMAIN_H
#define TDOMAIN_H

#include "precomp.h"
//#include <QTcpSocket>
//#include <QMainWindow>
//#include <QTreeView>
//#include <QStandardItemModel>
//#include <QTableView>
//#include <QStandardItem>
#include "database.h"
#include "publicstruct.h"
//#include "tabulationtemplate.h"
//#include "ctclientsocket.h"
//#include "ctsocketrunnable.h"
#include "ctmaintablemodel.h"

QT_BEGIN_NAMESPACE
namespace Ui { class TDomain; }
QT_END_NAMESPACE
//
class TDomain : public QMainWindow
{
    Q_OBJECT

public:
    TDomain(QWidget *parent = nullptr);
    ~TDomain();
    DbManager *m_dbMySql,*m_dbSqlLite;
    QVector<DomainQryAddrInfo> m_suffixQryAddr;
    QTreeView *m_treeView,*m_detailView;
    QStandardItemModel *m_domainCategoryModel;
    QStandardItemModel *m_tableModel;
private:
    Ui::TDomain *ui;

    QCheckBox *m_headerCheckbox;
    QTableView *m_tableView;
    QStringList m_strColsName;
    QStandardItemModel *m_domainInfoModel;
    QMenu *m_contextMenu,*m_domainInfoMenu,*m_addDomainsMenu,*m_rootMenu;
    QThreadPool *m_threadPool;
    QList<CategoryInfo> m_domainCategorys;
    //TabulationTemplate *m_tabTemplate;
    int requestCounter = 0,m_reqMax=0;
    QTimer *requestTimer;
//    QSize m_dialogSize;
//    QPoint m_centerPos;
    QTcpSocket socket;
    QVector<SocketDnInfo> m_dnVects;
    int m_pgBarTotal,m_pgBarCurrent;
    CtMainTableModel *m_mainModel;


    void initGlobalInfo();
    void initDb();
    void setupUI();
    void setupModels();
    void toggleAllSelected();
    void createCategoryRightPopMenu();
    void createDomainInfoRightPopMenu();
    void addNode(const QModelIndex &parentIndex, const QString &nodeName);//增加节点
//    bool getWhoisServerInfo(QString domainStr,QString & addrStr,int & port);
//    DomainDetailInfo getDomainDetailInfoById(int domainId);
//    void clientSocketRequest(QString sendMsg,QString ipAddr,int port);
    QAction *findActionByName(QMenu *menu, const QString &actionName);
    void refreshTableViewByCategoryId(int categoryId,QString filterSuffix,QString filterDnStatus,QString filterExpDate,QString filterRegStatus);
    void refreshTableViewByDnId(QString dnIds);
    void queryDomainWhois(QString dnStr);
    QMap<QString, QString> decodeWhoisInfoToMap(int dnType,QByteArray data);
    void saveNewDomain(QStringList dnStrs);
signals:
    void stopDnQryThread();
    void stopSqliteWriteThread();
    void sigShowDnToTableView(int rowid,DomainInfo dninfo);
private slots:
    void onAddBrotherCategory();
    void onAddChildCategory();
    void onDeleteCurrentCategory();
    void onRenameCategory();
    void onRefleshCategoryTree();
    void onCategorySelected();
//    QList<QStandardItem*> createDomainInfoRow(const DomainInfo &domainInfo);
    void initCategory();
    void slotCustomContextMenu(const QPoint &point);
    void toggleSelectAll(bool checked);
    void onTextImpDomainRecs();
    void onRuleCreateDomainRecs();
    void onDelCurrentRec();
    void onRefleshDomainTable(int categoryId);
    void slotDomainInfoPopMenu(const QPoint &point);
    void updateProgress(int progress);
    void onQryDomainWhois();
//    void onQryDomainDns();
//    void onQryDomainNetServer();
//    void onQryDomainPrice();
//    void dealRecvDataFromServer( QByteArray data);
    void slotShowToolTip(QModelIndex index);
    void slotRowDoubleClicked(const QModelIndex index);
    void on_actionDomainDic_triggered();
    void on_actionCreateDomain_triggered();
    void on_actionDomainWhois_triggered();
    void on_actionQryDomain_triggered();
    void on_actionAnalysisDomain_triggered();
    void on_actionConcernDomain_triggered();
    void on_actionExit_triggered();

    void on_btn_query_clicked();
    void on_btn_reset_clicked();
    void dealRecvDataFromServer(QByteArray data,QString reqParam);
    void onsetDomainsCategory();
    void sendNextRequest(SocketDnInfo sdi);
//    void on_actionproxymgr_triggered();
    void on_actionProxyMgr_triggered();
    void on_btn_stopQryDomain_clicked();
    void ShowDnToTableView(int rowid,DomainInfo dninfo);
    void onVerticalScrollStopped();
    void onHorizontalScrollStopped();
};
#endif // TDOMAIN_H
